﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using KafkaNet;
using KafkaNet.Model;

namespace Monitor.Core.Sensor
{
    class KafkaSensor : AbstractSensor
    {
        public KafkaSensor(int id, Uri uri)
            : base(id, uri)
        {
        }

        protected override ServiceStatus PingService()
        {
            var options = new KafkaOptions(this.Uri);
            using (var router = new BrokerRouter(options))
            {
                using (var client = new Producer(router))
                {
                    try
                    {
                        var t = client.GetTopic("test");
                        return ServiceStatus.Alive;
                    }
                    catch(Exception ex)
                    {
                        this._lastError = ex.Message;
                        return ServiceStatus.Dead;
                    }
                }
            }
        }
    }
}
